home *** CD-ROM | disk | FTP | other *** search
/ FANTA 97 / FANTA97A (backup).iso / FRONTPAG.SX / change_server.sh next >
Linux/UNIX/POSIX Shell Script  |  1997-09-18  |  27KB  |  1,078 lines

  1. #! /bin/sh
  2. #
  3. # Copyright 1996 Microsoft Corporation -- All Rights Reserved.
  4. #
  5. # $Revision: 1.19 $
  6. # $Date: 1997/09/16 19:14:43 $
  7. #
  8.  
  9. banner()
  10. {
  11. cat <<EOF
  12.  
  13.  
  14.  change_server.sh
  15.  
  16.  Revision$Revision: 1.19 $dummy
  17.  Date$Date: 1997/09/16 19:14:43 $dummy
  18.  
  19. This script will step the user through upgrading existing and installing 
  20. new servers and webs.  As with any software installation, a backup should be
  21. done before continuing.  It is recommended that the FrontPage installation
  22. directory, server configuration file directory, and all web content be 
  23. backed up before continuing with this installation.
  24.  
  25. EOF
  26.  
  27.  myprompt 'yYnN' "Are you satisfied with your backup of the system (y/n)" "N"
  28.  if [ $answer = n ] || [ $answer = N ]
  29.  then
  30.     exit 0
  31.  fi
  32.  echo
  33.  
  34.  return 0
  35. }
  36.  
  37. initialize()
  38. {
  39.   VERSION="3.0"
  40.   PATH=".:/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/etc"
  41.   NEWHTTPD="/usr/local/frontpage/currentversion/apache-fp/httpd"
  42.   UPGRADEVERSION=`$NEWHTTPD -v`
  43.   DEFAULTHTTPD="/usr/local/etc/httpd/httpd"
  44.  
  45. case "`echo 'x\c'`" in
  46.    'x\c')   echo="echo -n"    nnl= ;;      #BSD
  47.    x)       echo="echo"       nnl="\c" ;;  # Sys V
  48.    *)       echo "$0 quitting:  Can't set up echo." ; exit 1 ;;
  49. esac
  50.  
  51.  TAB="    "
  52.  system=`uname -a`
  53.  
  54.  case "$system" in
  55.      OSF1*)           machine="alpha" ;;
  56.      Linux*)          machine="linux" ;;
  57.      HP-UX*)          machine="hp700" ;;
  58.      AIX*)            machine="rs6000" ;;
  59.      IRIX*)           machine="sgi" ;;
  60.      SunOS*5.*sun4*)  machine="solaris" ;;
  61.      SunOS*4.*sun4*)  machine="sunos";;
  62.      SunOS*sun3*)     machine="sunos" ;;
  63.      *BSD/OS?3.0*)    machine="bsdi3" ;;
  64.      BSD/OS*)         machine="bsdi" ;;
  65.      SCO_SV*)         machine="sco5" ;;
  66.      *)               echo "ERROR:  Unsupported platform!  Uname is $system." 
  67.                       return 1
  68.                       ;;
  69.  esac
  70.  
  71.  awk=awk
  72.  lsg="ls -ld"
  73.  
  74.  case "$machine" in
  75.       sunos) awk=nawk
  76.              lsg="ls -ldg"
  77.              ;;
  78.     solaris) awk=nawk ;;
  79.         sgi) awk=nawk ;;
  80.  esac
  81.  
  82. }
  83.  
  84. checkuser()
  85. {
  86.  #
  87.  # Make sure we are running as root.
  88.  #
  89.  
  90.  echo "Checking user environment..."
  91. whoami=`whoami 2>/dev/null` || whoami=`/usr/bin/id | sed -e ' s/).*//; s/^.*(//;'`
  92.  retval=0
  93.  
  94.  if [ $whoami != "root" ]
  95.  then
  96.     echo "ERROR:  Logged in as $whoami.  Must be root to do this installation!"
  97.     return 1
  98.  else
  99.     echo "Logged in as root." 
  100.  fi
  101.  
  102.  echo "Setting umask to 002" 
  103.  umask 002
  104.  
  105.  return $retval
  106.  
  107. }
  108.  
  109. myprompt()
  110. {
  111.  answer="|"
  112.  until echo $1 | grep $answer >/dev/null
  113.  do
  114.     $echo "${2} [${3}]?  ${nnl}" 
  115.     read answer
  116.     if [ "$3" != "" ] && [ "$answer" = "" ]
  117.     then
  118.        answer=$3
  119.     fi
  120.  done
  121. }
  122.  
  123. InstallFPexe()
  124. {
  125.  echo
  126.  echo "Upgrading Apache Server to '$UPGRADEVERSION'"
  127.  echo
  128.  
  129.  checkPermissions ||
  130.  {
  131.      echo
  132.      echo "ERROR:  Unable to chown/chmod extensions!"
  133.      return 1
  134.  }
  135.  
  136.  httpdfile=""
  137.  while ( [ "$httpdfile" = "" ] || [ ! -f $httpdfile ] )
  138.  do
  139.      httpdfile=$DEFAULTHTTPD
  140.      $echo "Where is the current apache daemon located:  [$httpdfile] ${nnl}"
  141.      read location
  142.      if [ "$location" != "" ]
  143.      then
  144.         httpdfile=$location
  145.      fi
  146.  done
  147.  
  148.  version=`$httpdfile -v`
  149.  echo
  150.  $echo "${version}   ${nnl}"
  151.  
  152.  case $version in
  153.      $UPGRADEVERSION) echo "Server has already been upgraded!"
  154.                         echo "No upgrade necessary, continuing..."
  155.                         return 0
  156.                         ;;
  157.             *Apache*) echo "Upgrading..."
  158.                         mv $httpdfile ${httpdfile}.orig || 
  159.                         {
  160.                             echo
  161.                             echo "ERROR:  Unable to copy ${httpdfile} to ${httpdfile}.orig"
  162.                             return 1
  163.                         }
  164.  
  165.                         cp ${NEWHTTPD} ${httpdfile} || 
  166.                         {
  167.                             echo
  168.                             echo "ERROR:  Unable to copy ${fpexe} to ${httpdfile}"
  169.                             return 1
  170.                         }
  171.                         
  172.                         return 0
  173.                         ;;
  174.                      *) echo "This is not an Apache Server!"
  175.                         return 1
  176.                         ;;
  177.  esac
  178.  
  179.  return 0
  180. }
  181.  
  182. checkPermissions()
  183. {
  184.  retval=0
  185.  
  186.  fpexe="/usr/local/frontpage/version${VERSION}/apache-fp/_vti_bin/fpexe"
  187.  echo 
  188.  echo "Chowning $fpexe to root..." 
  189.  chown root $fpexe ||
  190.  {
  191.     echo "ERROR:  Unable to chown $fpexe to root" 
  192.     retval=1
  193.  }
  194.  
  195.  echo "Setting $fpexe to SUID..." 
  196.  chmod u+s $fpexe ||
  197.  {
  198.     echo "ERROR:  Unable to set SUID for $fpexe" 
  199.     retval=1
  200.  } 
  201.  
  202.  echo
  203.  
  204.  return $retval
  205.  
  206. }
  207.  
  208. UpgradeServers()
  209. {
  210.  cat <<EOF 
  211.  
  212. The file /usr/local/frontpage/currentversion/change_server_results.txt
  213. will contain Success/Fail status for the upgrades.  When the upgrade 
  214. has completed, you should examine this file to make sure that all of the 
  215. upgrades were successful.
  216.  
  217. EOF
  218.  
  219.  $echo "Hit enter to continue${nnl}" 
  220.  read continue
  221.  echo
  222.  
  223.  createdate=`date`
  224.  cat >/usr/local/frontpage/currentversion/change_server_results.txt <<EOF
  225. #
  226. # Server Upgrade Results
  227. #
  228. # Automatically generated by change_server.sh on $createdate
  229. #
  230. EOF
  231.  
  232.  for weconfigfile in /usr/local/frontpage/*.cnf
  233.  do
  234.     echo 
  235.     echo "Upgrading using configuration file:  "$weconfigfile 
  236.     if IsItApache $weconfigfile
  237.     then
  238.         if verifywebserver $weconfigfile
  239.         then
  240.             if UpgradeServer $weconfigfile
  241.             then
  242.                 echo "Upgrade Successful  $weconfigfile" >> /usr/local/frontpage/currentversion/change_server_results.txt
  243.             else
  244.                 echo "Upgrade Failed      $weconfigfile" >> /usr/local/frontpage/currentversion/change_server_results.txt
  245.                 echo "ERROR:  Server upgrade failed!"
  246.                 echo "Continuing with next server." 
  247.                 $echo "Hit enter to continue${nnl}" 
  248.                 read continue
  249.             fi
  250.         else
  251.             echo "Cancelling upgrade..."
  252.             echo "Upgrade Failed      $weconfigfile" >> /usr/local/frontpage/currentversion/change_server_results.txt
  253.         fi
  254.     fi
  255.  done
  256.  
  257. }
  258.  
  259. verifywebserver()
  260. {
  261.  weconfigfile="$1"
  262.  
  263.  conf=`basename $weconfigfile`
  264.  port=`echo  $conf | sed -e '
  265.      s/:/:/
  266.      tmulti
  267.      s/.cnf$//
  268.      s/.*[^0-9]//
  269.      q
  270.      :multi
  271.      s/.cnf$//'`
  272.  
  273.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e '
  274.              s/serverconfig://g'`
  275.  if [ ! -f "$configfile" ]
  276.  then
  277.      echo "$configfile does not exist."
  278.      return 1
  279.  fi
  280.   
  281.  servertype=`grep -i "^servertype:" $weconfigfile | sed -e 's/servertype://g'`
  282.  configfiledir=`dirname $configfile`"/"
  283.  
  284.  getdocroot $weconfigfile ||
  285.  {
  286.     echo "ERROR:  Unable to get DocumentRoot/UserDir" 
  287.     return 1
  288.  } 
  289.  
  290.  case $servertype in 
  291.       *pache*)   getHttpDirective $configfile AccessConfig $port
  292.                  if [ "$param" != "" ]
  293.                  then
  294.                     file=`basename $param`
  295.                     accessconffile="${configfiledir}${file}"
  296.                  else
  297.                     accessconffile="${configfiledir}access.conf"
  298.                  fi
  299.  
  300.                  if [ ! -f "$accessconffile" ]
  301.                  then
  302.                     echo "$accessconffile does not exist."
  303.                     return 1
  304.                  fi
  305.  
  306.                  ;;
  307.  esac
  308.  
  309.  servicesfile=${docroot}"/_vti_pvt/services.cnf"
  310.  
  311.  if [ ! -f "$servicesfile" ]
  312.  then
  313.      echo "There are no services to upgrade for this web."
  314.      return 1
  315.  fi
  316.  
  317.  return 0
  318. }
  319.  
  320. IsItApache()
  321. {
  322.  weconfigfile="$1"
  323.  
  324.  echo 
  325.  echo "Checking configuration file ${weconfigfile} for server type..."
  326.  servertype=`grep -i "^servertype:apache" $weconfigfile`
  327.      
  328.  if [ "$servertype" = "" ]
  329.  then
  330.      echo "Not apache server   $weconfigfile" >> /usr/local/frontpage/currentversion/change_server_results.txt
  331.      echo
  332.      echo "This is not an apache server!  No upgrade to be done."
  333.      return 1  
  334.  else
  335.      servertype=`echo $servertype | sed -e 's/servertype://g'`
  336.      if [ "$servertype" = "apache-fp" ]
  337.      then
  338.          echo "Already apache-fp   $weconfigfile" >> /usr/local/frontpage/currentversion/change_server_results.txt
  339.          echo
  340.          echo "This is already an apache-fp server!  No upgrade to be done."
  341.          return 1
  342.      fi
  343.  fi
  344.  
  345.  return 0
  346.  
  347. }
  348.  
  349. UpgradeServer()
  350. {
  351.  weconfigfile="$1"
  352.  
  353.  servertype=`echo $servertype | sed -e 's/servertype://g'`
  354.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e '
  355.             s/serverconfig://g'`
  356.  myprompt 'yYnN' "This is an ${servertype} server!  Would you like to upgrade it (y/n)" "Y"
  357.  if [ $answer = y ] || [ $answer = Y ]
  358.  then               
  359.      echo 
  360.      echo "Updating information in ${weconfigfile}"
  361.      echo "Moving $weconfigfile to ${weconfigfile}.orig"
  362.      mv $weconfigfile ${weconfigfile}.orig ||
  363.      (
  364.          echo "Unable to move $weconfigfile!"
  365.          return 1
  366.      )
  367.  
  368.      echo "Creating new $weconfigfile and setting servertype..."
  369.      sed -e s/servertype:.*/servertype:apache-fp/g ${weconfigfile}.orig > $weconfigfile ||
  370.      (
  371.          echo "Unable to create new $weconfigfile!  If the file has"
  372.          echo "been corrupted you should be able to replace it with"
  373.          echo "the backup (${weconfigfile}.orig)"
  374.          return 1 
  375.      )
  376.         
  377.      case $configfile in
  378.      *fakeconf*) SetConfigFile $weconfigfile $configfile || return 1 ;;
  379.      *) echo "Config file setting does not appear to be a fakeconf.  Continuing..." ;;
  380.      esac
  381.             
  382.      echo
  383.      echo "Preparing to upgrade FrontPage Server..."
  384.     
  385.      DoUpgrade $weconfigfile  ||
  386.      (
  387.          return 1
  388.      )
  389.  else
  390.      echo "User cancelled   $weconfigfile" >> /usr/local/frontpage/currentversion/change_server_results.txt
  391.      echo
  392.      echo "Server not upgraded!  Proceeding to the next server."
  393.  fi
  394.  
  395.  echo
  396.  
  397.  return 0
  398. }
  399.  
  400. chownexistingservers()
  401. {
  402.  retval=0
  403.  
  404.  echo "Preparing to chown webs..." 
  405.  cat <<EOF
  406.  
  407. Your webs have been upgraded to use the new Apache-fp Server.  The next step
  408. is to chown the web in order to guarantee that the extensions will work 
  409. properly.  At this point you have two options:
  410.  
  411.    1. This script will prompt you interactively for an owner and group of
  412.       each web and then perform the chown.  If you do not have a lot of 
  413.       webs you might want to choose this option.
  414.  
  415.    2. This script will generate a script, which you can edit to fill in the
  416.       owner and group for each web, to run at a later date.  If you have a
  417.       large number of webs you might want to choose this option.
  418.  
  419. EOF
  420.  
  421.      echo "Would you like to be prompted interactively for"
  422.      myprompt 'yYnN' "each webs owner/group (y/n)" "Y"
  423.      if [ $answer = y ] || [ $answer = Y ]
  424.      then
  425.         chownwebs 
  426.      else
  427.         generatechownscript $file  ||
  428.         (
  429.             echo "ERROR:  Server chown failed!  Continuing with next server." 
  430.             $echo "Hit enter to continue${nnl}" 
  431.             read continue
  432.         )
  433.      fi
  434.      return $retval
  435. }
  436.  
  437. chownwebs()
  438. {
  439.  retval=0
  440.  
  441.  for weconfigfile in /usr/local/frontpage/*.cnf
  442.  do
  443.      if grep Successful /usr/local/frontpage/currentversion/change_server_results.txt | grep ${weconfigfile} > /dev/null
  444.      then
  445.          chownWeb $weconfigfile
  446.      else
  447.          echo
  448.          echo "Web ${weconfigfile} was not upgraded."
  449.          echo "See /usr/local/frontpage/currentversion/change_server_results.txt" 
  450.          echo "Skipping chown..."
  451.      fi
  452.  
  453.  done
  454.  
  455.  return $retval
  456. }
  457.  
  458. chownWeb()
  459. {
  460.  weconfigfile=$1
  461.  
  462.  echo 
  463.  conf=`basename $weconfigfile`
  464.  webport=`echo  $conf | sed -e '
  465.      s/:/:/
  466.      tmulti
  467.      s/.cnf$//
  468.      s/.*[^0-9]//
  469.      q
  470.      :multi
  471.      s/.cnf$//'`
  472.  
  473.  port=$webport
  474.  
  475.  echo "Processing webs in port $webport..."
  476.  echo
  477.  
  478.  servertype=`grep -i "^servertype:" $weconfigfile | sed -e 's/servertype://g'`
  479.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e 's/serverconfig://g'`
  480.  configfiledir=`dirname $configfile`"/"
  481.  
  482.  getdocroot $weconfigfile ||
  483.  {
  484.     echo "ERROR:  Unable to get DocumentRoot/UserDir" 
  485.     return 1
  486.  } 
  487.  
  488.  servicesfile=${docroot}"/_vti_pvt/services.cnf"
  489.  
  490.  exec 4<&0
  491.  exec <$servicesfile
  492.  n=0
  493.  while read service
  494.  do 
  495.     if [ $service = "/" ]
  496.     then
  497.        webname=""
  498.        webtext="root web"
  499.        web=""
  500.     else
  501.        webname="$service"
  502.        webtext="$service"
  503.        web="-w $webname"
  504.     fi
  505.     exec 5<&0
  506.     exec 0<&4
  507.  
  508.     getdocroot $weconfigfile ||
  509.     {
  510.         echo "ERROR:  Unable to get DocumentRoot/UserDir" 
  511.         return 1
  512.     } 
  513.  
  514.     case $service in
  515.        /~*)  owner=`echo $service | sed -e 's/\///'`
  516.  
  517.              webowner=`echo $service | sed -e 's/\/~//'`
  518.              homedir=`finger $webowner |  awk ' { if (NR==2) print $2}'`
  519.  
  520.              if [ -d "${homedir}/${userdir}" ]
  521.              then
  522.                  echo "Web ${webtext} on port ${webport} will be owned by ${webowner}"
  523.                  defwebgroup=`$lsg ${homedir}/${userdir} | awk ' { print $4}'`
  524.                  exists=0
  525.              else
  526.                  exists="${homedir}/${userdir}"
  527.              fi
  528.              ;;
  529.        *)    if [ -d "${docroot}/${service}" ]
  530.              then
  531.                  defwebowner=`$lsg ${docroot}${service} | awk ' { print $3}'`
  532.                  defwebgroup=`$lsg ${docroot}${service} | awk ' { print $4}'`
  533.                  $echo "Who should own web ${webtext} on port ${webport} [${defwebowner}]:  ${nnl}"
  534.                  read webowner
  535.                  if [ "$webowner" = "" ]
  536.                  then
  537.                      webowner=$defwebowner
  538.                  fi
  539.                  exists=0
  540.              else
  541.                  exists="${docroot}/${service}"
  542.  
  543.              fi
  544.              ;;
  545.     esac
  546.  
  547.     if [ "$exists" = "0" ]
  548.     then
  549.         $echo "What should the group for web ${webtext} on port ${webport} be [${defwebgroup}]:  ${nnl}"
  550.         read webgroup
  551.         if [ "$webgroup" = "" ]
  552.         then
  553.             webgroup=$defwebgroup
  554.         fi
  555.  
  556.  
  557.         /usr/local/frontpage/version${VERSION}/bin/fpsrvadm.exe -o chown -p $webport $web -xUser $webowner -xGroup $webgroup ||
  558.         {
  559.             echo 
  560.             echo "ERROR:  Unable to chown web ${webtext} in port ${webport}"
  561.             $echo "Hit enter to continue${nnl}" 
  562.             read continue
  563.         }
  564.     else
  565.         echo "ERROR:  web $service - $exists does not exist!  Skipping to next web."  
  566.     fi
  567.         exec 0<&5
  568.  done
  569.  exec <&4
  570.  
  571. }
  572.  
  573. generatechownscript()
  574. {
  575.  retval=0
  576.  scriptout="/usr/local/frontpage/version${VERSION}/fp_chown.sh"
  577.  createdate=`date`
  578.  
  579.  cat <<EOF
  580.  
  581. A script will be generated in ${scriptout} 
  582. which you can edit to chown your webs at a future date.  You will need 
  583. to edit the script and set the owner and group for each web before 
  584. running the script.
  585.  
  586. EOF
  587.  
  588.  cat >$scriptout <<EOF 
  589. #! /bin/sh
  590. #
  591. #
  592. # Copyright 1996 Microsoft Corporation -- All Rights Reserved.
  593. #
  594. # Automatically generated by change_server.sh on $createdate
  595. #
  596. # You will need to edit this script before running it.  Change each 
  597. # <OWNER> and <GROUP> to reflect the ownership/group that you want 
  598. # set for the web.
  599. #
  600. # Example:  80 /testweb webowner webgroup
  601. #
  602.  
  603. VERSION="3.0"
  604.  
  605. chown_web()
  606. {
  607.  port=\$1
  608.  webname=\$2
  609.  webowner=\$3
  610.  webgroup=\$4
  611.  
  612.  retval=0
  613.  
  614.  if [ "\$webowner" = "<OWNER>" ] || [ "\$webgroup" = "<GROUP>" ]
  615.  then
  616.      echo "Owner/Group not specified for web \$webname on \$port!  Skipping to next web..."
  617.  else
  618.      if [ "\$webname" != "/" ]
  619.      then
  620.         webname=\`echo \$webname | sed -e 's%^/%%g'\`
  621.         webtext="\$webname"
  622.         web="-w \$webname"
  623.      else
  624.         webtext="root web"
  625.         web=""
  626.      fi
  627.      echo
  628.      echo "Chowning web \${webtext} in port \${port} to owner \${webowner} group \${webgroup}"
  629.      /usr/local/frontpage/version3.0/bin/fpsrvadm.exe -o chown -p \$port  \$web  -xUser \$webowner -xGroup \$webgroup
  630.  fi
  631. }
  632.  
  633. while read port webname webowner webgroup
  634. do
  635.     chown_web \$port \$webname \$webowner \$webgroup
  636. done <<ENDCHOWN
  637. EOF
  638.  
  639.  for weconfigfile in /usr/local/frontpage/*.cnf
  640.  do
  641.      if grep Successful /usr/local/frontpage/currentversion/change_server_results.txt | grep ${weconfigfile} > /dev/null
  642.      then 
  643.          addChownWeb $weconfigfile
  644.      else
  645.          echo
  646.          echo "Web ${weconfigfile} was not upgraded."
  647.          echo "See /usr/local/frontpage/currentversion/change_server_results.txt" 
  648.          echo "Skipping chown..."
  649.      fi
  650.  done
  651.  
  652.  echo "ENDCHOWN" >>$scriptout
  653.  
  654.  chmod 764 $scriptout
  655.  
  656.  return $retval
  657. }
  658.  
  659. addChownWeb()
  660. {
  661.  echo 
  662.  conf=`basename $weconfigfile`
  663.  webport=`echo  $conf | sed -e '
  664.      s/:/:/
  665.      tmulti
  666.      s/.cnf$//
  667.      s/.*[^0-9]//
  668.      q
  669.      :multi
  670.      s/.cnf$//'`
  671.  
  672.  port=$webport
  673.  
  674.  echo "Adding webs in port ${webport} to chown script..."
  675.  servertype=`grep -i "^servertype:apache" $weconfigfile | sed -e 's/servertype://g'`
  676.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e 's/serverconfig://g'`
  677.  configfiledir=`dirname $configfile`"/"
  678.  case $servertype in 
  679.      *pache-fp*) getdocroot $weconfigfile ||
  680.                  {
  681.                      echo "ERROR:  Unable to get DocumentRoot/UserDir" 
  682.                      return $retval
  683.                  } 
  684.                  ;;
  685.               *) echo "Not an apache-fp web! Skipping to next web..." 
  686.                  return $retval
  687.                  ;;
  688.  esac
  689.  
  690.  servicesfile="${docroot}/_vti_pvt/services.cnf"
  691.  if [ -r $servicesfile ]
  692.  then
  693.      exec 4<&0
  694.      exec <$servicesfile
  695.      n=0
  696.      while read service
  697.      do 
  698.         if [ $service = "/" ]
  699.         then
  700.             webtext="root web"
  701.         else
  702.             webtext="$service"
  703.         fi
  704.         case $service in
  705.            /~*)  owner=`echo $service | sed -e 's/\///'`
  706.                  webowner=`echo $service | sed -e 's/\/~//'`
  707.                  homedir=`finger $webowner |  awk ' { if (NR==2) print $2}'`
  708.                  if [ -d "${homedir}/${userdir}" ]
  709.                  then
  710.                      webgroup=`$lsg ${homedir}/${userdir} | awk ' { print $4}'`
  711.                      exists=0
  712.  
  713.                  else
  714.                      exists="${homedir}/${userdir}"
  715.                  fi
  716.                  ;;
  717.              *)  if [ -d "${docroot}/${service}" ]
  718.                  then
  719.                      webowner=`$lsg ${docroot}${service} | awk ' { print $3}'`
  720.                      webgroup=`$lsg ${docroot}${service} | awk ' { print $4}'`
  721.                      exists=0
  722.                  else
  723.                      exists="${docroot}/${service}"
  724.                  fi
  725.                  ;;
  726.         esac
  727.  
  728.      if [ "$exists" = "0" ]
  729.      then
  730.         echo "web ${webtext}"
  731.         echo "$webport $service $webowner $webgroup" >> $scriptout
  732.      else
  733.         echo "ERROR:  web ${webtext}- Path $exists does not exist!  Skipping to next web."  
  734.      fi        
  735.      done
  736.      exec <&4
  737.  else
  738.      echo "Unable to read $servicesfile! Skipping to next port."
  739.  fi
  740.  
  741. }
  742.  
  743. SetConfigFile()
  744. {
  745.  defconfigfile=`echo $2 | sed -e 's/fakeconf\///g'`
  746.  
  747.  configfile=""
  748.  while ( [ "$configfile" = "" ] || [ ! -f $configfile ] )
  749.  do
  750.      $echo "Server config filename: [${defconfigfile}]  ${nnl}" 
  751.      read configfile
  752.      if [ "$configfile" = "" ]
  753.      then
  754.         configfile="$defconfigfile"
  755.      fi
  756.  done
  757.                            
  758.  echo "Setting serverconfig to $configfile..."
  759.  mv $weconfigfile ${weconfigfile}.bck ||
  760.  {
  761.     echo "Unable to update $weconfigfile!"
  762.     return 1
  763.  }
  764.  sed -e s%serverconfig:.*%serverconfig:$configfile%g ${1}.bck > $1  ||
  765.  {
  766.     echo "Unable to create new $weconfigfile!"
  767.     echo "If the file has been corrupted you should be able to replace it with"
  768.     echo "the backup file (${weconfigfile}.orig)"
  769.     rm ${weconfigfile}.bck
  770.     return 1 
  771.  }
  772.  
  773.  rm ${weconfigfile}.bck                          
  774.  return 0
  775. }
  776.  
  777. DoUpgrade()
  778. {
  779.  retval=0
  780.  weconfigfile="$1"
  781.  
  782.  bindir="/usr/local/frontpage/version${VERSION}/bin/"
  783.  
  784.  conf=`basename $weconfigfile`
  785.  port=`echo  $conf | sed -e '
  786.     s/:/:/
  787.     tmulti
  788.     s/.cnf$//
  789.     s/.*[^0-9]//
  790.     q
  791.     :multi
  792.     s/.cnf$//'`
  793.  
  794.  echo "Upgrading server "$port 
  795.  
  796.  cd /usr/local/frontpage/version"$VERSION"/bin
  797.  fpsrvadm.exe -o upgrade -p $port -type apache-fp
  798.  
  799.  return $retval
  800. }
  801.  
  802. getparam() {
  803. #
  804. # gets the value of parameters from the config file
  805. #
  806.     param=`egrep -i "^[ $TAB]*$1[ $TAB]" $2 | awk '{print $2}'` || return 1
  807.     return 0;
  808. }
  809.  
  810. getdocroot()
  811. {
  812.  weconfigfile=$1
  813.  virtweb=`echo  $weconfigfile | sed -e '
  814.          s/:/:/
  815.          tmulti
  816.          s/.cnf$//
  817.          s/.*[^0-9]//
  818.          q
  819.          :multi
  820.          s/:[0-9]*.cnf$//'`
  821.  virtweb=`basename $virtweb`
  822.  
  823.  port=`echo  $weconfigfile | sed -e '
  824.      s/:/:/
  825.      tmulti
  826.      s/.cnf$//
  827.      s/.*[^0-9]//
  828.      q
  829.      :multi
  830.      s/.cnf$//'`
  831.  
  832.  servertype=`grep -i "^servertype:" $weconfigfile | sed -e 's/servertype://g'`
  833.  configfile=`grep -i "^serverconfig:" $weconfigfile | sed -e '
  834.              s/serverconfig://g
  835.              s/fakeconf.*\///'`
  836.  
  837.  echo
  838.  echo "Getting DocumentRoot and UserDir."
  839.  
  840.  if [ ! -f "$configfile" ]
  841.  then
  842.      echo "$configfile does not exist."
  843.      return 1
  844.  fi
  845.  
  846.  configfiledir=`dirname $configfile`"/"
  847.   
  848.  docroot=""
  849.  
  850.  case $weconfigfile in
  851.       *:*) getHttpVirtualDirective $configfile $port DocumentRoot
  852.            docroot=$param
  853.  
  854.            if [ "$docroot" = "" ]
  855.            then
  856.                echo "VirtualHost block does not contain DocumentRoot directive."
  857.                getHttpDirective $configfile ResourceConfig $port
  858.                if [ "$param" != "" ]
  859.                then
  860.                    file=`basename $param`
  861.                    resconffile="${configfiledir}${file}"
  862.                else
  863.                    resconffile="${configfiledir}srm.conf"
  864.                fi
  865.                echo "Getting DocumentRoot from $resconffile."
  866.                getparam DocumentRoot $resconffile
  867.                docroot=$param
  868.            fi
  869.  
  870.            getHttpVirtualDirective $configfile $port UserDir
  871.            userdir=$param
  872.  
  873.            if [ "$userdir" = "" ]
  874.            then
  875.                echo "VirtualHost block does not contain UserDir directive."
  876.                getHttpDirective $configfile ResourceConfig $port
  877.                resconffile=$param
  878.                if [ "$param" != "" ]
  879.                then
  880.                    file=`basename $param`
  881.                    resconffile="${configfiledir}${file}"
  882.                else
  883.                    resconffile="${configfiledir}srm.conf"
  884.                fi
  885.                echo "Getting UserDir from $resconffile."
  886.                getparam UserDir $resconffile
  887.                userdir=$param
  888.            fi
  889.            ;;
  890.         *) case $servertype in 
  891.                 *etscape*) echo "Getting DocumentRoot from ${configfiledir}obj.conf."
  892.                            docroot=`grep -i 'document-root' ${configfiledir}obj.conf`
  893.                            docroot=`echo $docroot | sed -e'
  894.                            s/.*root="//
  895.                            s/".*//'`
  896.                            
  897.                            echo "Getting userdir from ${configfiledir}obj.conf."
  898.                            userdir=`grep -i 'from="/~"' ${configfiledir}obj.conf`
  899.                            userdir=`echo $docroot | sed -e'
  900.                            s/.*subdir="//
  901.                            s/".*//'`
  902.                            ;;
  903.  
  904.                         *) getHttpDirective $configfile ResourceConfig $port
  905.                            if [ "$param" != "" ]
  906.                            then
  907.                                file=`basename $param`
  908.                                resconffile="${configfiledir}${file}"
  909.                            else
  910.                                resconffile="${configfiledir}srm.conf"
  911.                            fi
  912.  
  913.                            if [ ! -f "$resconffile" ]
  914.                            then
  915.                                echo "ERROR: $resconffile does not exist!"
  916.                                return 1
  917.                            fi
  918.  
  919.                            echo "Getting DocumentRoot from $resconffile."
  920.                            getparam DocumentRoot $resconffile
  921.                            docroot=$param
  922.  
  923.                            echo "Getting UserDir from $resconffile."
  924.                            getparam UserDir $resconffile
  925.                            userdir=$param
  926.                            ;; 
  927.            esac  
  928.            ;;
  929.  esac
  930.  
  931.  if [ ! -d "$docroot" ]
  932.  then
  933.      echo "ERROR:  ${docroot} does not exist!"
  934.      return 1
  935.  fi
  936.  
  937.  if [ "$docroot" = "" ]
  938.  then
  939.      echo "ERROR:  DocumentRoot not defined!"
  940.      return 1
  941.  fi
  942.  
  943.  if [ "$userdir" = "" ]
  944.  then
  945.      echo "WARNING:  UserDir not defined."
  946.  fi
  947.  
  948.  echo
  949.  echo "DocumentRoot: $docroot"
  950.  
  951.  if [ "$userdir" = "" ]
  952.  then
  953.      echo "WARNING:  UserDir not defined."
  954.  else
  955.      echo "UserDir: $userdir"
  956.  fi
  957.  
  958.  echo
  959.  
  960.  return 0
  961.  
  962. }
  963.  
  964. getHttpDirective()
  965. {
  966.  configfile=$1
  967.  directive=$2
  968.  port=$3
  969.  
  970.  case $port in
  971.     *:*) getHttpVirtualDirective $configfile $port $directive ;;
  972.       *) getHttpRootDirective $configfile $directive ;;
  973.  esac
  974.  
  975.  if [ "$param" = "" ]
  976.  then
  977.      echo "Directive $directive not found."
  978.  else 
  979.      echo "Found Directive $directive, value $param."
  980.  fi
  981. }
  982.  
  983. getHttpRootDirective()
  984. {
  985.  configfile=$1
  986.  directive=$2
  987.  
  988.  mc_directive=`$awk "
  989.                BEGIN {
  990.                    newstring = \"\";
  991.                    oldstring = \"$directive\";
  992.                    strlen = length(oldstring);
  993.                    for ( i = 1; i <= strlen; ++i ) {
  994.                        char = substr(oldstring, i, 1)
  995.                        newstring = newstring \"[\" toupper(char) tolower(char) \"]\";
  996.                    };
  997.                    print newstring}"`
  998.  
  999.  param=`cat $configfile | $awk "
  1000.             /^[^#]* *< *[Vv][Ii][Rr][Tt][Uu][Aa][Ll][Hh][Oo][Ss][Tt]/,/^[^#]* *< *\/[Vv][Ii][Rr][Tt][Uu][Aa][Ll][Hh][Oo][Ss][Tt]/ { next }
  1001.             /^[^#]* *$mc_directive[ $TAB]/  { print \\\$2 }"` 
  1002.  
  1003.  return 0
  1004.  
  1005. }
  1006.  
  1007. getHttpVirtualDirective()
  1008. {
  1009.  configfile=$1
  1010.  port=$2
  1011.  directive=$3
  1012.  
  1013.  virtweb=`echo  $port | sed -e 's/:[0-9]*.$//'`
  1014.  virtweb=`basename $virtweb`
  1015.  
  1016.  mc_directive=`$awk "
  1017.                BEGIN {
  1018.                    oldstring = \"$directive\"
  1019.                    newstring = \"\";
  1020.                    strlen = length(oldstring);
  1021.                    for ( i = 1; i <= strlen; ++i ) {
  1022.                        char = substr(oldstring, i, 1)
  1023.                        newstring = newstring \"[\" toupper(char) tolower(char) \"]\";
  1024.                    };
  1025.                    print newstring }"`
  1026.  
  1027.  
  1028.  param=`cat $configfile | $awk "
  1029.                           BEGIN { value = \"\" }
  1030.                               { x=0 }
  1031.                               /^[^#]* *< *[Vv][Ii][Rr][Tt][Uu][Aa][Ll][Hh][Oo][Ss][Tt] +$virtweb/,/^[^#]* *< *\/[Vv][Ii][Rr][Tt][Uu][Aa][Ll][Hh][Oo][Ss][Tt]/ { x=1 }
  1032.                               /^[^#]* *$mc_directive[ $TAB]/  { if (x==1) value =\\\$2 }
  1033.                           END { print value }"`
  1034.  
  1035.  if [ "$param" = "" ]
  1036.  then
  1037.     getHttpRootDirective $configfile $directive
  1038.  fi 
  1039.  
  1040. }
  1041.  
  1042. error()
  1043. {
  1044.  #
  1045.  # Print an error message and exit the program
  1046.  #
  1047.  
  1048.  echo 
  1049.  echo "Exiting due to an error!  Please fix the error and try again." 
  1050.  echo 
  1051.  
  1052.  exit 1
  1053. }
  1054.  
  1055. #
  1056. # This is the main part of the shell script.
  1057. #
  1058.  
  1059.   initialize
  1060.   checkuser || error
  1061.   banner
  1062.   InstallFPexe || error                   # Install fpexe
  1063.   UpgradeServers || error                 # Now upgrade the servers
  1064.   chownexistingservers || error           # Now chown the webs
  1065.  
  1066.   cat <<EOF
  1067.  
  1068.   Installation completed!  You will need to stop the old server daemon
  1069.   and start the new one before your webs will work properly.
  1070.   Exiting... 
  1071. EOF
  1072.   exit 0
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.